/*

BlackRabbit - OpenSource IDE.
@author Edward Sarkisyan (edward.sarkisyan@gmail.com)
Use LGPL (http://www.gnu.org/copyleft/lesser.html)

*/

#include "notificationsarea.h"
#include "ui_notificationsarea.h"
#include <QPainter>

NotificationsArea::NotificationsArea(QWidget *parent) :
    QWidget(parent),
    m_ui(new Ui::NotificationsArea)
{
    m_ui->setupUi(this);
    animation = new QPropertyAnimation(this);
}

NotificationsArea::~NotificationsArea()
{
    delete animation;
    delete m_ui;
}

void NotificationsArea::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void NotificationsArea::on_addNotify_clicked()
{
    Notify *m_not = new Notify(this);
    nots.push_back(m_not);
    m_ui->horizontalLayout->insertWidget(0, m_not);
}

void NotificationsArea::paintEvent( QPaintEvent * e)
{
    Q_UNUSED(e)
    QStyleOption opt;
    opt.init( this );

    QPainter p( this );
    style()->drawPrimitive( QStyle::PE_Widget, &opt, &p, this );
}

void NotificationsArea::notify(NOTIFICATION_INFORMATION info)
{
    Notify *m_not = new Notify(this);
    m_not->setText(info.Message);
    nots.push_back(m_not);
    m_ui->horizontalLayout->insertWidget(0, m_not);
    if(animation == 0)
        return;
    animation->setTargetObject(m_not);
    animation->setPropertyName("size");
    animation->setStartValue(QSize(100,0));
    animation->setEndValue(QSize(100,20));
    animation->start();
}
